Page({
  data: {
    left: [
      { name: '绿茶', id: "2", active: 'active' },
      { name: '红茶', id: "1", active: '' },
      { name: '白茶', id: "3", active: '' },
      { name: '普洱茶', id: "4", active: '' },
      { name: '乌龙茶', id: "5", active: '' },
      { name: '黑茶', id: "6", active: '' },
    ],
    num: [{ name: '绿茶' }],
    bet: [],
    botton: [],
    tid:"1",
    winH:0,
    winWL:0,
    winWR:0,
  },

  changeOil: function (e) {
    var id = e.target.dataset.id;
    var pos = this.data.left;
    var name = '绿茶';
    var that = this;
    for (var index in pos) {
      if (pos[index].id == id) {
        pos[index].active = 'active';
        name = pos[index].name;
      } else {
        pos[index].active = '';
      }
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
    // 热门搜索
    wx.request({
      url: getApp().AppUrl + '/index.php/api/api/hot_search_ct',
      data: {
        teacase_id: "" + id
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        var botton = res.data;
        that.setData({
          botton: botton
        })
      }
    })
    wx.request({
      url: getApp().AppUrl + 'index.php/api/api/getTeaArea',
      method: 'GET',
      data: {
        id: "" + id
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        wx.hideLoading()
        that.setData({
          left: pos,
          num: [{ name: name }],
          bet: res.data,
          tid:id,
        })
      }
    })
  },
  // 热门搜索跳转
  hot_search: function (e) {
    var e = e.target.dataset;
    if (!e.its_id) {
      var urls = '../Allot/Allot?id=' + e.bangdan_id + "&tid=" + e.teacase_id + '&hid=' + e.teaarea_id
    } else {
      if (e.bangdan_id == 1) {
        var urls = getApp().Craftsman+'?sid=' + e.its_id + '&id=' + e.bangdan_id + '&tid=' + e.teacase_id + '&hid=' + e.teaarea_id + "&ins= " + e.ins + '&biaozhi=1';
      } else if (e.bangdan_id == 2) {
        var urls = getApp().brand+'?sid=' + e.its_id + '&id=' + e.bangdan_id + '&tid=' + e.teacase_id + '&hid=' + e.teaarea_id + "&ins= " + e.ins + '&biaozhi=1';
      } else {
        var urls = getApp().Treasures+'?sid=' + e.its_id + '&id=' + e.bangdan_id + '&tid=' + e.teacase_id + '&hid=' + e.teaarea_id + "&ins= " + e.ins + '&biaozhi=1';
      }
    }
    // console.log(urls);
    wx.navigateTo({
      url: urls
    })
  },
  locationNumll404: function () {
    wx.navigateTo({
      url: '../Nullpage/Nullpage'
    })
  },
  loactionAllot: function (e) {
    wx.navigateTo({
      url: '../Allot/Allot'
    })
  },
  locationsAllot: function (e) {
    // console.log(e)
    var hid = e.target.dataset.id;
    var tid = this.data.tid;
    wx.navigateTo({
      url: '../Allot/Allot?id=1&hid='+hid+'&tid='+ tid
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 选择id是去哪个榜单
    // hid是区域
    // Tid是茶类
    var Tid = options.Tid;
    var pos = this.data.left;
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        var winH = res.windowHeight-52;
        var winWL = res.windowWidth*20/100 - 1;
        var winWR = res.windowWidth * 80 / 100;
        console.log(winH)
        that.setData({
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth,
          winH: winH,
          winWR: winWR,
          winWL: winWL,
        })
      }
    });
    wx.showLoading({
      title: '加载中',
      mask: true,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
    console.log(Tid)
    for (var index in pos){
      if (pos[index].id == Tid){
        pos[index].active = 'active';
        var name = pos[index].name;
      } else {
        pos[index].active = '';
      }
    } 
    // 热门搜索
    wx.request({
      url: getApp().AppUrl + '/index.php/api/api/hot_search_ct',
      data: {
        teacase_id: "" + Tid
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data);
        var botton = res.data;
        that.setData({
          botton: botton
        })
      }
    })
    wx.request({
      url: getApp().AppUrl + 'index.php/api/api/getTeaArea',
      method: 'GET',
      data: {
        id: "" + Tid
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        wx.hideLoading()
        console.log(res.data)
        that.setData({
          num: [{ name: name }],
          left: pos,
          bet:res.data,
          tid:Tid
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})